{% extends "base.html" %}

{% block title %}报警信息{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col">
            <div class="d-flex justify-content-between align-items-center">
                <h2>报警信息</h2>
                <a href="{{ url_for('alarm.rules') }}" class="btn btn-primary">
                    <i class="fas fa-cog me-1"></i>报警规则设置
                </a>
            </div>
        </div>
    </div>

    <!-- 活跃报警 -->
    <div class="row mb-4">
        <div class="col">
            <div class="card border-danger">
                <div class="card-header bg-danger text-white">
                    <h5 class="card-title mb-0">未处理报警</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>监控点</th>
                                    <th>参数</th>
                                    <th>当前值</th>
                                    <th>阈值</th>
                                    <th>级别</th>
                                    <th>时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for alarm in active_alarms %}
                                <tr>
                                    <td>{{ alarm.point.name }}</td>
                                    <td>{{ alarm.parameter }}</td>
                                    <td>{{ alarm.current_value }}</td>
                                    <td>{{ alarm.threshold }}</td>
                                    <td>
                                        <span class="badge bg-{{ 'warning' if alarm.level == 'warning' else 'danger' }}">
                                            {{ '警告' if alarm.level == 'warning' else '危险' }}
                                        </span>
                                    </td>
                                    <td>{{ alarm.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                    <td>
                                        <form action="{{ url_for('alarm.resolve_alarm', alarm_id=alarm.id) }}" method="POST" class="d-inline">
                                            <button type="submit" class="btn btn-success btn-sm">标记已处理</button>
                                        </form>
                                    </td>
                                </tr>
                                {% else %}
                                <tr>
                                    <td colspan="7" class="text-center">暂无未处理的报警</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 历史报警 -->
    <div class="row">
        <div class="col">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">历史报警</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>监控点</th>
                                    <th>参数</th>
                                    <th>报警值</th>
                                    <th>阈值</th>
                                    <th>级别</th>
                                    <th>报警时间</th>
                                    <th>处理时间</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for alarm in resolved_alarms %}
                                <tr>
                                    <td>{{ alarm.point.name }}</td>
                                    <td>{{ alarm.parameter }}</td>
                                    <td>{{ alarm.current_value }}</td>
                                    <td>{{ alarm.threshold }}</td>
                                    <td>
                                        <span class="badge bg-{{ 'warning' if alarm.level == 'warning' else 'danger' }}">
                                            {{ '警告' if alarm.level == 'warning' else '危险' }}
                                        </span>
                                    </td>
                                    <td>{{ alarm.created_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                    <td>{{ alarm.resolved_at.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                                </tr>
                                {% else %}
                                <tr>
                                    <td colspan="7" class="text-center">暂无历史报警记录</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 